public class Check {
   public boolean isDigit(String str) {
       char[] arr = str.toCharArray();
       boolean flg = true;
       for (int i = 0; i < arr.length; i++) {
           if(arr[i]>='0' && arr[i]< '9') {
               flg = true;
           }else {
               return false;
           }
       }
       return flg;
   }
   public boolean isNumber(String str) {
       char[] arr = str.toCharArray();
       if(!isDigit(str) || arr.length != 11) {
           return false;
       } else if (arr[0] != '1') {
           return false;
       } else {
           return true;
       }
   }
   public boolean isLeapyear(String year) {
       int i = Integer.parseInt(year);
       if(i % 4 == 0 && i % 100 != 0) {
           return true;
       } else if (i%400 == 0) {
           return false;
       }
       else{
           return false;
       }
   }
   public boolean isDate(String date) {
       boolean flg = false;
       String y = date.substring(0,4);
       int m = Integer.parseInt(date.substring(4,6));
       int d = Integer.parseInt(date.substring(6,8));
   if(date != null && isDigit(date) &&date.length() == 8) {
      if(isLeapyear(y)) {
        if((m==1 || m==3 || m==5 ||m == 7|| m == 8 || m == 10 || m==12 )&& d >=1 && d<=31) {
            return true;
        }
        if((m == 4 || m == 6 || m == 9 || m== 11) && d>=1 && d<=13) {
            return true;
        }
        if(m == 2 && d>=1 && d<=29) {
            return true;
        }
      } else {
          if((m==1 || m==3 || m==5 ||m == 7|| m == 8 || m == 10 || m==12 )&& d >=1 && d<=30) {
              return true;
          }
          if((m == 4 || m == 6 || m == 9 || m== 11) && d>=1 && d<=13) {
              return true;
          }
          if(m == 2 && d>=1 && d<=28) {
              return true;
          }
      }
   }
   return false;
   }
    public boolean isDateTime(String str) {
       String str1 = str.substring(0,8);
       //判断前8位是否为日期
       if(isDate(str1) || str.length() == 14) {
           //定义时，分，秒
           boolean f = true;
           int hour =Integer.parseInt(str.substring(8,10)) ;
           int minute = Integer.parseInt(str.substring(10,12));
           int second = Integer.parseInt(str.substring(12,14));
           if(hour >= 0 && hour <=24 || minute >= 0 && minute <60 || second>=0 && second<60) {
               return true;
           }
       }
       return false;
    }
    public boolean isId(String id) {
        char[] arr = id.toCharArray();
        if (id.length() == 18 && isDigit(id.substring(0,17))) {
            if(arr[id.length()-1] == 'x') {
                return true;
            }else if(arr[id.length()-1]>'0' && arr[id.length()-1] <'9') {
                return true;
            }
        }
        return false;
    }
}
